package bitWork;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: tao
 * Date: 2023-12-09
 * Time: 14:25
 */
public class Work2 {
    public static void main(String[] args) {
        //二分查找
        int[] arr = {1,2,3,4,5,6};
        int left = 0;//左下标
        int right = arr.length - 1;//右下标
        int x = 3;//要查找的数字
        while (left < right) {
            int mid = (left + right) / 2;//中间下标
            if(arr[mid] < x) {
                left = mid + 1;
            } else if(arr[mid] > x) {
                right = mid + 1;
            } else {
                //arr[mid] = x
                System.out.println("下标是：" + mid);
                break;
            }
        }
    }
}
